package com.example.customizedgroupmessage;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.widget.Button;
import android.widget.ListView;
import android.view.View;
import java.util.ArrayList;



public class SMSCustomWord extends Activity {
	ArrayList<Custom> arrCustom;
	DBHelper mHelper;
	SQLiteDatabase db;
	ArrayList<Custom> items;
	
	public static final int REQUEST_CODE_SMSSEND=1007;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sms_custom_word);
		
		arrCustom = new ArrayList<Custom>();
		arrCustom.clear();
		
		Custom temp;
		String id = null;
		String name = null;
		String custom=null;
		String organization=null;
		String groupname=null;
		mHelper=new DBHelper(this);
		db = mHelper.getReadableDatabase();
		Cursor cursor;
		cursor = db.rawQuery("SELECT _id, name, status, organization, phone, groupname FROM sms", null);
		while (cursor.moveToNext()) {
			id = cursor.getString(0);
			name = cursor.getString(1);
			custom=cursor.getString(2);
			organization=cursor.getString(3);
			groupname=cursor.getString(5);
			temp = new Custom(id, name, custom, organization, groupname);
			temp.setId(id);
			temp.setName(name);
			temp.setCustom(custom);
			temp.setOrganization(organization);
			temp.setGroupName(groupname);
			arrCustom.add(temp);
		}
		cursor.close();
		mHelper.close();  
		// 어댑터 준비
				CustomAdapter CustomAdapter;
				CustomAdapter = new CustomAdapter(this, R.layout.sms_word, arrCustom);
				
            
				// 리스트뷰에 어탭터 연결
				ListView list = (ListView)findViewById(R.id.sms_custom_list);
				list.setAdapter(CustomAdapter);
		
			
				
				
				Button btnNext = (Button)findViewById(R.id.btnNext);
				btnNext.setOnClickListener(
					new Button.OnClickListener() {
						public void onClick(View v){
						/*	EditText ed1 = (EditText)findViewById(R.id.specialEdit);
							if(ed1.getText().toString().equals("")){
								 Toast.makeText(getApplicationContext(), "편빈칸을 입력하세요!", Toast.LENGTH_LONG).show();
								   //빈칸일 경우 토스토 알림 
								           
								  }*/
								 
							 Intent intent = new Intent(getBaseContext(), SMSSendActivity.class);
								startActivityForResult(intent, REQUEST_CODE_SMSSEND);
							
							
						}
				});

	}	


	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
}



class Custom {

	private String id;
	private String name;
    private String custom;
    private String organization;
    private String groupname;
	public Custom(String _id, String _name, String _custom, String _organization, String _groupname){
		this.id = _id;
		this.name = _name;
		this.custom=_custom;
		this.organization=_organization;
		this.groupname=_groupname;
	}
	
	public void setCustom(String _custom) {
		// TODO Auto-generated method stub
		custom=_custom;
	}

	public String getId(){
		return id;
	}
	public String getName(){
		return name;
	}
	public String getSpecialMsg(){
		return custom;
	}
	public String getOrganization(){
		return organization;
	}
	public String getGroupName(){
		return groupname;
	}
	public void setId(String _id) {
		id = _id;
	}
	public void setName(String _name) {
		name = _name;
	}
	public void setOrganization(String _organization) {
		organization = _organization;
	}
	public void setGroupName(String _groupname) {
		groupname = _groupname;
	}
}

